# Contributor: Peter Bui <pnutzh4x0r@gmail.com>
# Maintainer: Julien Voisin <julien.voisin@dustri.org>
pkgname=py3-pygments
pkgver=2.18.0
pkgrel=0
pkgdesc="Syntax highlighting package written in Python"
url="https://pygments.org/"
arch="noarch"
license="BSD-2-Clause"
depends="python3"
makedepends="py3-setuptools py3-gpep517 py3-wheel py3-installer"
checkdepends="py3-pytest py3-lxml py3-wcag-contrast-ratio"
subpackages="$pkgname-pyc $pkgname-doc"
source="https://files.pythonhosted.org/packages/source/P/Pygments/pygments-$pkgver.tar.gz
	build-with-setuptools.patch
	"
builddir="$srcdir/pygments-$pkgver"
options="!check" # causes issues when bootstrapping (py3-pytest depends on this)

replaces="py-pygments" # Backwards compatibility
provides="py-pygments=$pkgver-r$pkgrel" # Backwards compatibility

# secfixes:
#   2.7.4-r0:
#     - CVE-2021-20270

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m pytest
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/Pygments*.whl

	mkdir -p "$pkgdir"/usr/bin
	ln -s pygmentize "$pkgdir"/usr/bin/pygmentize-3
}

doc() {
	local destdir="$subpkgdir/usr/share/doc/$pkgname"

	cd "$builddir"

	install -m 644 -D doc/pygmentize.1 \
		"$subpkgdir"/usr/share/man/man1/pygmentize.1

	mkdir -p "$destdir"
	cp AUTHORS CHANGES LICENSE "$destdir"/

	# Note: The documentation in the doc directory needs to be generated
	# by py-sphinx
	cp -R ./doc/docs/* "$destdir"/

	default_doc
}

sha512sums="
2f696fed7f2120f9e3bd5f3d2837a5d6b883434b8d0f68d039c2620213508638cedf1517375019809720d56fc52f07e3bddd0defc4707703ace5d707908c00fb  pygments-2.18.0.tar.gz
5843e84f597cb249c2ca4c88b224a7e737b204ce8cbb136005576739126b1f72d2cb89b12bcb23cd863d5f6447951ad767d37a38cbcb5d8db70f1f4fb5c11a76  build-with-setuptools.patch
"
